/*
 * Copyright @ JuCheap All rights reserved.
 * 
 * 功能描述:数据过滤模型文件(此文件为系统模板生成,请勿修改)
 * 作者: JuCheap
 * 时间: 04/03/2020 14:24:39
 */
using JuCheap.Core.Infrastructure.Extentions;
using System;

namespace JuCheap.Core.Model
{
    /// <summary>
    /// SysVisitLog Model
    /// </summary>	
    public partial class SysVisitLogFilter
	{
        /// <summary>
        /// 日期范围
        /// </summary>
        [ExcludeField]
        public DateTime[] VisitDateRange { get; set; }

        /// <summary>
        /// 获取开始日期
        /// </summary>
        /// <returns></returns>
        [ExcludeField]
        public DateTime? GetStartDate()
        {
            var date = GetDateByIndex(0);
            if (date.HasValue)
            {
                return date.Value.Date.AddMilliseconds(-1);
            }
            return null;
        }

        /// <summary>
        /// 获取结束日期
        /// </summary>
        /// <returns></returns>
        [ExcludeField]
        public DateTime? GetEndDate()
        {
            var date = GetDateByIndex(1);
            if (date.HasValue)
            {
                return date.Value.Date.AddDays(1);
            }
            return null;
        }

        private DateTime? GetDateByIndex(int index)
        {
            if (VisitDateRange != null && VisitDateRange.Length >= index + 1)
            {
                return VisitDateRange[index];
            }
            return null;
        }
    }
}
